package com.handpay.zztong.hp.ui;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.log.HPLog;

/**
 * @author sxshi on 2017/1/12.
 * @email:emotiona_xiaoshi@126.com
 * @describe:Describe the function  of the current class
 */

public class CustomProgressDialog extends ProgressDialog {
    private TextView msgView;
    private CharSequence mMessage;
    private LinearLayout progress_dialog_ll;
    private boolean isInVisiable;

//    public TextView getMsgView() {
//        return msgView;
//    }
//
//    public void setMsgView(TextView msgView) {
//        this.msgView = msgView;
//    }

    @Override
    public void setMessage(CharSequence message) {
        if (msgView != null) {
            msgView.setText(message);
        } else {
            mMessage = message;
        }
    }

    public CustomProgressDialog(Context context) {
        super(context);
    }

    public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.progress_dialog);
        progress_dialog_ll = (LinearLayout) super.findViewById(R.id.progress_dialog_ll);
        if (isInVisiable) {
            progress_dialog_ll.setVisibility(View.INVISIBLE);
        }
        msgView = (TextView) super.findViewById(R.id.tv_loading);
        msgView.setText(mMessage);
        msgView.setVisibility(TextUtils.isEmpty(mMessage) ? View.GONE : View.VISIBLE);
        WindowManager.LayoutParams params = getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.WRAP_CONTENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(params);
    }

    public void setInVisiable(boolean isInVisiable) {
        this.isInVisiable = isInVisiable;
//            progress_dialog_ll.setVisibility(View.INVISIBLE);
//        }
    }

}
